package cn.uexpo.lhz.biz.impl;

import cn.uexpo.lhz.biz.ItemRulesBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.ItemRulesMapper;
import cn.uexpo.lhz.domain.ItemRules;
import cn.uexpo.lhz.domain.ItemRulesExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemRulesBizImpl implements ItemRulesBiz {

	@Autowired
	private ItemRulesMapper itemRulesMapper;


	@Override
	public int insert(ItemRules record) throws BOException {
		return itemRulesMapper.insert(record);
	}

	@Override
	public int insertSelective(ItemRules record) throws BOException {
		return itemRulesMapper.insertSelective(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		return itemRulesMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteEntity(ItemRules record) throws BOException {
		return itemRulesMapper.deleteByPrimaryKey(record.getId());
	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		int no=0;
		if (null!=ids) {
			for (Integer id : ids) {
				no=itemRulesMapper.deleteByPrimaryKey(id);
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int delete(List<ItemRules> records) throws BOException {
		int no=0;
		if (null!=records&&records.size()>0){
			for (ItemRules itemRulesEntity : records) {
				no=itemRulesMapper.deleteByPrimaryKey(itemRulesEntity.getId());
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int deleteByExample(ItemRulesExample example) throws BOException {
		return itemRulesMapper.deleteByExample(example);
	}

	@Override
	public int updateByPrimaryKey(ItemRules record) throws BOException {
		return itemRulesMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updateByPrimaryKeySelective(ItemRules record) throws BOException {
		return itemRulesMapper.updateByPrimaryKeySelective(record);
	}
	@Override
	public int updateByExampleSelective(ItemRules record, ItemRulesExample example) throws BOException {
		return itemRulesMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int updateByExample(ItemRules record, ItemRulesExample example) throws BOException {
		return itemRulesMapper.updateByExample(record, example);
	}


	@Override
	public ItemRules selectByPrimaryKey(Integer id) throws BOException {
		return itemRulesMapper.selectByPrimaryKey(id);
	}

	@Override
	public ItemRules selectByUniqueCode(String uniqueCode) throws BOException {
		return null;
	}

	@Override
	public List<ItemRules> selectByExample(ItemRulesExample example) throws BOException {
		return itemRulesMapper.selectByExample(example);
	}

	@Override
	public long countByExample(ItemRulesExample example) throws BOException {
		return itemRulesMapper.countByExample(example);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest, ItemRulesExample example) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<ItemRules> records = (List<ItemRules>) itemRulesMapper.selectByExample(example);
		return PageUtils.getPageResult(pageRequest, new PageInfo<ItemRules>(records));
	}

	@Override
	public List<ItemRules> selectByExampleWithBLOBs(ItemRulesExample example) throws BOException {
		return itemRulesMapper.selectByExampleWithBLOBs(example);
	}

	@Override
	public int updateByExampleWithBLOBs(ItemRules record, ItemRulesExample example) throws BOException {
		return 0;
	}

	@Override
	public int updateByPrimaryKeyWithBLOBs(ItemRules record) throws BOException {
		return itemRulesMapper.updateByPrimaryKeyWithBLOBs(record);
	}
}
